package cz.zcu.fav.ratdroid.activity.calendar.day;

import org.joda.time.LocalDate;

import cz.zcu.fav.ratdroid.R;
import cz.zcu.fav.ratdroid.activity.calendar.provider.ICalendarDataProvider;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

public class DayActivity extends FragmentActivity
{
	public static String PRESELECTED_DATE = "preselected.date";
	public static String PRESELECTED_DATETIME = "preselected.datetime";

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		LocalDate preselectedDate = (LocalDate) getIntent()
				.getSerializableExtra(PRESELECTED_DATE);
		ICalendarDataProvider asyncDataProvider = (ICalendarDataProvider) getIntent()
				.getSerializableExtra(
						ICalendarDataProvider.CALENDAR_DATA_PROVIDER_IDENTIFIER);

		if (savedInstanceState == null)
		{
			Bundle bundle = new Bundle();
			bundle.putSerializable(PRESELECTED_DATE, preselectedDate);
			bundle.putSerializable(
					ICalendarDataProvider.CALENDAR_DATA_PROVIDER_IDENTIFIER,
					asyncDataProvider);

			ScheduleFragment frag = (ScheduleFragment) Fragment.instantiate(
					this, ScheduleFragment.class.getName(), bundle);
			FragmentTransaction t = getSupportFragmentManager()
					.beginTransaction();
			t.replace(R.id.calendar1, frag);
			t.commit();
		}
	}
}
